home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-MIPS / DELAY.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  1KB  |  53 lines

  1. #ifndef __ASM_MIPS_DELAY_H
  2. #define __ASM_MIPS_DELAY_H
  3.  
  4. extern __inline__ void __delay(int loops)
  5. {
  6.     __asm__ __volatile__ (
  7.         ".set\tnoreorder\n"
  8.         "1:\tbnez\t%0,1b\n\t"
  9.         "subu\t%0,1\n\t"
  10.         ".set\treorder"
  11.         :"=r" (loops)
  12.         :"0" (loops));
  13. }
  14.  
  15. /*
  16.  * division by multiplication: you don't have to worry about
  17.  * loss of precision.
  18.  *
  19.  * Use only for very small delays ( < 1 msec).  Should probably use a
  20.  * lookup table, really, as the multiplications take much too long with
  21.  * short delays.  This is a "reasonable" implementation, though (and the
  22.  * first constant multiplications gets optimized away if the delay is
  23.  * a constant)
  24.  */
  25. extern __inline__ void __udelay(unsigned long usecs, unsigned long lps)
  26. {
  27.     usecs *= 0x000010c6;        /* 2**32 / 1000000 */
  28.     __asm__("multu\t%0,%1\n\t"
  29.         "mfhi\t%0"
  30.         :"=r" (usecs)
  31.         :"0" (usecs),"r" (lps));
  32.     __delay(usecs);
  33. }
  34.  
  35. #ifdef __SMP__
  36. #define __udelay_val cpu_data[smp_processor_id()].udelay_val
  37. #else
  38. #define __udelay_val loops_per_sec
  39. #endif
  40.  
  41. #define udelay(usecs) __udelay((usecs),__udelay_val)
  42.  
  43. /*
  44.  * The different variants for 32/64 bit are pure paranoia. The typical
  45.  * range of numbers that appears for MIPS machines avoids overflows.
  46.  */
  47. extern __inline__ unsigned long muldiv(unsigned long a, unsigned long b, unsigned long c)
  48. {
  49.     return (a*b)/c;
  50. }
  51.  
  52. #endif /* __ASM_MIPS_DELAY_H */
  53.